import pytest
import os
from util.get_path import get_path
import subprocess


def invoke(cmd):
    output, erors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    o = output.decode("utf-8")
    return o


if __name__ == '__main__':
    xml_report_path = os.path.join(get_path(), "report", "xml")
    html_report_path = "/Users/lijianpei/PycharmProjects/api_demo/report/html"
    print(xml_report_path)
    print(html_report_path)
    args = ["-s", "-q", "test_case/test_demo.py", "--alluredir", xml_report_path]
    pytest.main(args)
    cmd = "allure generate %s -o %s --clean" % (xml_report_path, html_report_path)
    ret = invoke(cmd)
    print(ret)
